﻿using FlyingEye.Models;
using FlyingEye.Repositories;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace FlyingEye.Services
{
    public class CutterService : ICutterService
    {
        private readonly CutterRepository _repository;

        private ILogger<CutterService> _logger;

        public CutterService(CutterRepository cutterRepository, ILogger<CutterService> logger)
        {
            _repository = cutterRepository;
            _logger = logger;
        }

        public async Task RecordCutterInfoAsync(CutterInformation information)
        {
            try
            {
                await _repository.InsertAsync(information);
            }
            catch (JsonReaderException ex)
            {
                _logger.LogError(ex, "Json 消息格式错误。");
                throw ex;
            }
        }
    }
}
